package pe.com.bbva.ge.domain.configuracion;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import pe.com.bbva.ge.domain.base.Auditoria;
import pe.com.bbva.ge.domain.base.Identificador;


/**
 * The persistent class for the CFG_POSICION database table.
 * 
 */
@Entity
@Table(name="CFG_POSICION")
public class Posicion extends Identificador {
	private static final long serialVersionUID = 1L;
	
	@Id
	@Column(unique = true, nullable = false, precision = 19)
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "SEQ_POSICION")
	@TableGenerator(name = "SEQ_POSICION", 
	table = Posicion.SEQ_TABLA, 
	pkColumnName = Posicion.SEQ_TABLA_PK, 
	initialValue = 1, 
	valueColumnName = Posicion.SEQ_TABLA_COLUMN, 
	pkColumnValue = "pe.com.bbva.ge.domain.configuracion.Posicion", 
	allocationSize = 1)	
	private long id;
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	
	@Transient
	public String getComboLabel()
	{
		return tipo.getNombre() + " - " + nombre;
	}
	
	/*@Override
	public int hashCode() {
		HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(31, 7);
		hashCodeBuilder.append(id);
		return hashCodeBuilder.toHashCode();
	}

	@Override
	public boolean equals(Object obj) {
		boolean equals = false;
		if (obj instanceof Posicion){
			Posicion bean = (Posicion) obj;
			EqualsBuilder equalsBuilder = new EqualsBuilder();
			equalsBuilder.append(id, bean.id);
			equals = equalsBuilder.isEquals();
		}
		return equals;
	}*/
	
	//Remplazable POR JPA

	private String descripcion;

	private String nombre;

	//bi-directional many-to-one association to Atm
	@OneToMany(mappedBy="proveedor", cascade=CascadeType.ALL)
	private List<Atm> atms;

	//uni-directional many-to-one association to Valor
	@ManyToOne
	@JoinColumn(name="TIPO")
	private Valor tipo;

	//uni-directional many-to-one association to Valor
	@ManyToOne
	@JoinColumn(name="ESTADO")
	private Valor estado;

	public String getDescripcion() {
		return this.descripcion;
	}

	public void setDescripcion(String descripcion) {
		this.descripcion = descripcion;
	}

	public String getNombre() {
		return this.nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public List<Atm> getAtms() {
		return this.atms;
	}

	public void setAtms(List<Atm> atms) {
		this.atms = atms;
	}

	public Atm addAtm(Atm atm) {
		getAtms().add(atm);
		atm.setProveedor(this);

		return atm;
	}

	public Atm removeAtm(Atm atm) {
		getAtms().remove(atm);
		atm.setProveedor(null);

		return atm;
	}

	public Valor getTipo() {
		return this.tipo;
	}

	public void setTipo(Valor tipo) {
		this.tipo = tipo;
	}

	public Valor getEstado() {
		return this.estado;
	}

	public void setEstado(Valor estado) {
		this.estado = estado;
	}

}